import React from 'react'
// ===================================================================== 
const { $fn, $Lazy } = window
// ===================================================================== Lazy
const FormItem 	= $Lazy.load(()=>import('#cpt/form/submit-item'))
// ===================================================================== component
const Index = ({ info={}, disabled, multiple, className, r }) => {
	const [ img, setImg ] = React.useState()
	const [ pic, setPic] = React.useState()
	const [ report, setReport] = React.useState()

	React.useEffect( () => {
		setTimeout(()=>{
			const { content, is_coll_pic, is_upload_report_form } = info || {}
			
			const { report_form_imgs } = content || {}
			if($fn.isString(report_form_imgs)){
				setImg( report_form_imgs.indexOf('pdf') || report_form_imgs.indexOf('jpg') || report_form_imgs.indexOf('png') ? report_form_imgs : null  )
			}else{
				setImg(null)
			}
			
			setPic( +is_coll_pic === 1)
			setReport( +is_upload_report_form === 1)
		},1)
	},[info])
	
	return (
		<div className={className}>
			{
				pic && <FormItem title='图形' r={r} name='imgs' disabled={disabled} type='upload' code={126} multiple={multiple} />
			}
			{
				report && (
					<FormItem title='报告单上传' r={r === false ? false : true} name='report_form_imgs' fileType={['pdf','img']} type='upload' btnText='上传文件' mode='button' disabled={disabled}
						controls = {[
							{ label:'查看上传报告单', disabled:!img, ghost:true, onClick: ()=>{
								window.open( $fn.getImagePrefix(img) )
							}}
						]}
						onChanged={({value})=>{
							setImg(value)
						}}
					/>
				)
			}
		</div>
	)
}

export default Index